package com.sskj.bibi.util;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.TextView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.sskj.bibi.R;
import com.sskj.common.base.App;
import com.sskj.common.util.ClickUtil;
import com.sskj.lib.bean.BuySellEnum;

public class TipBibiUtil {
    /**
     * 购买弹窗
     * @param context
     * @param isBuy 购买 true
     * @param isMarket 市价 true
     * @param price 购买价格
     * @param num 购买数量
     * @param allMoney 交易额
     * @param onTipSure 回调
     */
    public static void showTradeInfo(Context context, boolean isBuy, boolean isMarket,
                                     String price, String num, String allMoney, OnTipSure onTipSure) {
        MaterialDialog dialog = new MaterialDialog.Builder(context)
                .customView(R.layout.bibi_dialog_trade_info_tip, false)
                .autoDismiss(false)
                .cancelable(false)
                .show();
        View customeView = dialog.getCustomView();

        ((TextView) customeView.findViewById(R.id.tvDirection)).setTextColor(ContextCompat.getColor(App.INSTANCE, isBuy ? BuySellEnum.BUY.getColorRes() : BuySellEnum.SELL.getColorRes()));
        ((TextView) customeView.findViewById(R.id.tvDirection)).setText(isBuy ? BuySellEnum.BUY.getTitle() : BuySellEnum.SELL.getTitle());
        ((TextView) customeView.findViewById(R.id.tvType)).setText(isMarket ? App.INSTANCE.getString(R.string.bibi_tipBibiUtil1) : App.INSTANCE.getString(R.string.bibi_tipBibiUtil2));

        ((TextView) customeView.findViewById(R.id.tvPrice)).setText(price);
        ((TextView) customeView.findViewById(R.id.tvNum)).setText(num);
        if (isBuy && isMarket) {
            ((TextView) customeView.findViewById(R.id.tvTitlePrice)).setText(App.INSTANCE.getString(R.string.bibi_tipBibiUtil3));
            ((TextView) customeView.findViewById(R.id.tvPrice)).setText(allMoney);
        }
        ClickUtil.click(customeView.findViewById(R.id.tvCancel), () -> {
            dialog.dismiss();
        });
        ClickUtil.click(customeView.findViewById(R.id.tvSure), () -> {
            dialog.dismiss();
            onTipSure.onSure();
        });
    }

    public interface OnTipSure {
        void onSure();
    }
}
